Repository navigation
feat(agents): 统计支持拆分维度、筛选,并给出每组速度中位数与首字平均耗时 - #245
Conversation
agentSessions.stats 新增可选 splitBy(agent/model/provider/modelProvider)、models、providers、failed、search、detail,groupBy 新增 provider、modelProvider、all;agentSessions.calls 新增 models、providers、search。agents/usage 的分组和回答保持不变。
There was a problem hiding this comment.
Devin Review found 1 potential issue.
1 flag not posted on this PR by your GitHub settings — view it in Devin Review. (Configure)
| Some(call.session_id.as_str()), | ||
| entry.cwd.as_deref(), | ||
| ] | ||
| .map(|field| field.map(str::to_lowercase)); |
There was a problem hiding this comment.
🟡 Usage search misses Greek directory matches
When users search for οσ, CallSelector drops calls from /work/ΟΣ because lowercasing turns the final Σ into ς. The usage totals and request table both omit those calls.
Learn more
Usage statistics and the request table both use the same search filter through summarize and calls. Session validation accepts Unicode working directories, which for_each_call supplies to the filter. with_search lowercases each query word separately. Lowercasing a complete directory uses a contextual final sigma, so the substring comparison can reject spellings that differ only in case.
Example: With calls recorded in /work/ΟΣ, a search for οσ compares οσ against /work/ος and drops the calls. Both commands must keep them under the case-insensitive search contract.
Recommended fix: Apply Unicode case folding to both query words and candidate fields, as the recent-project search does with caseless::default_case_fold_str. Keep the existing whitespace splitting and all-words matching, and add a regression test with a Unicode working directory.
Was this helpful? React with 👍 or 👎 to provide feedback.
背景
桌面端 AI 管理窗口的「用量 → 概览」要对照 magpie 的用量页做到:每日图表按模型/供应商/Agent 拆分堆叠、指标可切换(令牌/费用/请求/速度/首字耗时)、顶部有模型/供应商/成败/搜索筛选。现在的
agentSessions.stats一次只能按一个维度分组,没有筛选,也没有每组的速度和首字耗时,这些逻辑属于可复用的统计逻辑,按仓库规则放在 Core,桌面端只负责显示(桌面端 PR:Lithe-IDEA #2597)。改动
agentSessions.stats(宿主命令):splitBy(agent/model/provider/modelProvider):在groupBy之后再拆一层,例如groupBy: "day"+splitBy: "model"得到每天每个模型一条 Summary,第二个键放在summary.split。不带splitBy时回答和以前一样。非法值以agentSessions.invalidSplit拒绝。groupBy新增provider、modelProvider、all(全部调用合成一组,用于不能由其他分组相加得到的总数,如速度中位数、缓存命中率)。这三个名字只给宿主,agents/usage(插件)的可用分组不变。models、providers、failed、search:同时作用于summaries和speeds。models/providers里的空字符串表示“没有写明模型/供应商的调用”;search按空白分词,每个词都要在模型、请求的模型、供应商、Agent、会话 ID、工作目录之一里出现(不区分大小写)。最多 64 个模型、64 个供应商,每个名字和搜索文字最多 256 字节,超出以agentSessions.invalidFilter拒绝。detail: true时,每个 Summary 增加speed {calls, medianTokensPerSecond, lowerBound}(该组中有速度且输出至少 100 令牌的调用的速度中位数,规则和speeds一致)和firstToken {calls, averageMs}(成功且记录了首字时间的调用的平均首字耗时)。不带detail时两者都不出现,所以宿主和插件两条路径的summaries仍逐字节一致(既有的“小时统计与共享 fixture 一致”测试继续有效)。agentSessions.calls:新增models、providers、search,规则同上;原有的model、failed不变,所有给出的筛选必须同时满足。实现上新增
stats::CallSelector(stats 与 calls 共用同一份筛选判断),Summarizer增加split_by()、detailed(),速度排名与分组速度共用ranked_speed。契约
shared/plugins/contract/v1/README.md的agentSessions.stats、agentSessions.calls两段补充了新参数、新分组名、新返回字段、错误码agentSessions.invalidSplit/agentSessions.invalidFilter,以及旧 Core 的表现(把新字段当未知字段拒绝)。agents0 内补充,不升能力版本;没有新增或修改插件宿主方法、通知、能力版本,所以 API 总表和“宿主方法(按 API 编号)”索引不需要加行。验证
cargo test -p lithe-agent-sessions stats(12 个,新增 4 个:拆分、供应商分组、每组速度/首字、筛选)cargo test -p lithe-agent-runtime(含新增stats_split_filter_and_detail_the_calls:拆分键、detail、各类筛选在 stats 与 calls 上结果一致、非法splitBy/筛选的拒绝、插件路径不变)cargo fmt --all -- --check、cargo clippy -p lithe-agent-sessions -p lithe-agent-runtime --all-targets -- -D warningsnode shared/plugins/scripts/verify-docs.mjssdk-e2e.mjs。后续
桌面端 Draft #2597 临时固定这个 PR 的 head 提交;合入后换成 main 提交。